<?php
namespace app\common\model;
use think\Model;

/**
 * 验证码
 */
class SendCode extends Model {
	protected $insert = ['add_time','validate_time'];

	protected function setAddTimeAttr(){
		return time();
	}

	protected function setValidateTimeAttr(){
		return time()+120;
	}

	/**
	 * [验证码校验]
	 * @param  string  $mobile [手机号]
	 * @param  string  $code   [验证码]
	 * @param  integer $type   [方式 1：注册 2：绑定手机号、切换手机号  3：找回密码]
	 * @return [type]          [description]
	 */
	public function checkCode($mobile='',$code='',$type=0){
		/*if(empty($mobile) || !is_mobile($mobile)){
			return ['status'=>0,'msg'=>'请输入有效的手机号码'];
		}
		if(empty($code)){
			return ['status'=>0,'msg'=>'请输入短信验证码'];
		}
		$res = $this->where(['account'=>$mobile,'code'=>$code,'type'=>$type])->order('add_time desc')->find();
	
		if(!$res){
			return ['status'=>0,'msg'=>'短信验证码错误'];
		}
		if(time() > $res['validate_time']){
			return ['status'=>0,'msg'=>'短信验证码过期'];
		}*/
		return ['status'=>1,'msg'=>'短信验证码正确'];
	}
}
